#ifndef GROUPMODEL_H
#define GROUPMODEL_H

#include "groupitem.h"
#include "baza/grupa.h"
#include <QAbstractListModel>

class GroupModel: public QAbstractListModel
{
    Q_OBJECT

    Q_PROPERTY(int count READ count NOTIFY countChanged)

public:
    enum GroupRoles  {
        RoleGroupName = Qt::DisplayRole,
        RoleId = Qt::UserRole,
        RoleIndex = Qt::UserRole+1,
        RolePriority = Qt::UserRole+2
    };

    GroupModel(QObject *parent = 0);

    void addGroup(const Grupa &grupa, int index);
    void clear();

    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    int count();

    Q_INVOKABLE GroupItem* get(int index);
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;

    QModelIndex indexFromItem(const GroupItem *item) const;

private slots:
    void handleItemChange();

signals:
    void countChanged(int newCount);


private:
    QList<GroupItem*> m_groupItems;
};
#endif // GROUPMODEL_H
